import asyncio
import time

async def child_task(num, parent_num):
    print(f"Child {num} (Parent {parent_num}) started at {time.time()}")
    await asyncio.sleep(1)  # 模拟异步IO操作
    print(f"Child {num} (Parent {parent_num}) finished at {time.time()}")

async def parent_task(num):
    print(f"Parent {num} started at {time.time()}")
    await asyncio.gather(
        child_task(1, num),
        child_task(2, num),
    )
    print(f"Parent {num} finished at {time.time()}")

if __name__ == "__main__":
    import nest_asyncio
    nest_asyncio.apply()
    async def main():
        # 并发执行两个父任务，每个父任务内部再并发执行两个子任务
        await asyncio.gather(
            parent_task(1),
            parent_task(2),
        )

    asyncio.run(main())